const common = {

}

common.calculationHeight = function (num) {
    return (num / 750) * window.screen.width;
}
common.isExist = function (cart, commodity) {
    var index = -1;
    for (var i = 0; i < cart.commodityList.length; i++) {
        if (cart.commodityList[i].properties == commodity.properties && cart.commodityList[i].commodityName == commodity.commodityName) {
            index = i;
            break;
        }
    }
    return index;
}
common.isExistById = function (cart, commodity) {
    var count = 0;
    for (var i = 0; i < cart.commodityList.length; i++) {
        if (cart.commodityList[i].commodityId == commodity.commodityId) {
            count += cart.commodityList[i].count
        }
    }
    return count;
}
common.getAllPrice = function (list) {
    let allPrice = 0;
    for (var i = 0; i < list.length; i++) {
        if (list[i].selected) {
            allPrice =
                parseFloat(allPrice) +
                parseFloat(list[i].price) *
                list[i].count;
        }
    }
    return allPrice;
}
common.getSelectedCommodities = function (list) {
    let commodities = [];
    for (var i = 0; i < list.length; i++) {
        if (list[i].selected) {
            commodities.push(list[i])
        }
    }
    return commodities;
}
// common.isAllChecked = function (cart) {
//     var allChecked = true;
//     for (var i = 0; i < cart.commodityList.length; i++) {
//         if (!cart.commodityList[i].selected) {
//             allChecked = false;
//             break;
//         }
//     }
//     console.log("是否全选",allChecked)
//     return allChecked;
// }

export default common